package com.china.school.processor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class BeanFactoryPostProcessorTest implements BeanFactoryPostProcessor {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("BeanFactoryPostProcessorTest.xml");
        System.out.println(ctx.getBean("beanFactoryPostProcessorTest"));
        System.out.println(ctx.getBean("user"));


    }

    /**
     自定义beanDefinition的信息，
     比如动态注册一个对象
     BeanDefinitionRegistryPostProcessor

     */
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println("--------------");
        BeanDefinition user = configurableListableBeanFactory.getBeanDefinition("user");
        user.setBeanClassName("com.china.school.dao.impl.PersonDaoImpl");
    }
}
